/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kweative.model.apt;

import com.kweative.util.ArrayUtil;
import java.util.HashSet;
import java.util.LinkedList;

/**
 *
 * @author henrik
 */
public class MethodDefinition {
    private ClassDefinition clazz;
    private String name;
    private String returnType;
    private String[] body = new String[0];
    private HashSet<VariableDefinition> parms = new HashSet<VariableDefinition>();

    public MethodDefinition(ClassDefinition clazz,String name, String returnType) {
        this.clazz = clazz;
        this.name = name;
        this.returnType = returnType;
    }

    public void setBody(String[] body) {
        this.body = body;
    }
    public void addParm(String className,String name) {
        parms.add(new VariableDefinition(className, name));
        clazz.addImport(className);
    }
    public HashSet<VariableDefinition> getParms() {
        return parms;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("public ").append(returnType).append(" ").append(name).append("(");
        boolean first = true;
        for(VariableDefinition parm:parms) {
            if (!first)
                sb.append(",");
            sb.append(parm.toString());
            first = false;
        }
        sb.append(") {\n\t\t");
        sb.append(ArrayUtil.join(body,"\n\t\t"));
        sb.append("\n\t}\n");
        return sb.toString();
    }

}
